/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Actividad;

import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
/*__________________________________________________________________________________________*/
/*__________________________________________________________________________________________*/
/**
 * <hr>
 * ActividadView: En esta clase se encuantran los metodos necesarios para implementar una ventana
 * que le permite a un docente agregar una actividad en el sistema
 * 
 * @author Gaston
 * <hr>
 */
/*__________________________________________________________________________________________*/
/*__________________________________________________________________________________________*/
public class ActividadView extends javax.swing.JFrame {

    /**
     * Creates new form ActividadView
     */
    public ActividadView() {
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jTitulo = new javax.swing.JLabel();
        jAgregar = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTabla = new javax.swing.JTable();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jTitulo.setText("Administracion de Actividad");

        jAgregar.setText("Agregar");

        jTabla.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null}
            },
            new String [] {
                "", "Codigo actividad", "Descripcion", "Codigo materia", "Fecha entrega"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.Boolean.class, java.lang.String.class, java.lang.String.class, java.lang.String.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                true, false, false, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane1.setViewportView(jTabla);
        jTabla.getColumnModel().getColumn(0).setResizable(false);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 619, Short.MAX_VALUE)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jAgregar, javax.swing.GroupLayout.PREFERRED_SIZE, 82, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(202, 202, 202)
                        .addComponent(jTitulo)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jTitulo, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 181, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 30, Short.MAX_VALUE)
                .addComponent(jAgregar, javax.swing.GroupLayout.PREFERRED_SIZE, 37, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jAgregar;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTabla;
    private javax.swing.JLabel jTitulo;
    // End of variables declaration//GEN-END:variables

    
    /**
     * setModelTabla(): este metodo modifica el modelo de una tabla, dependiendo del parametro que reciba
     * puede crear una tabla vacia o si recibe una tabla con elementos inserta esta nueva tabla en la tabla anterior
     * 
     * @param tabla 
     */
    public void setModeloTabla(DefaultTableModel tabla){
        if (tabla == null){ 
            jTabla.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "", "Codigo actividad", "Descripcion", "Codigo materia", "Fecha entrega"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.Boolean.class, java.lang.String.class, java.lang.String.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                true, false, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });       
        } else {
            this.jTabla.setModel(tabla);
        }    
        jTabla.getTableHeader().setReorderingAllowed(false);
        jScrollPane1.setViewportView(jTabla);
        jTabla.getColumnModel().getColumn(0).setResizable(false);
        jTabla.getColumnModel().getColumn(0).setPreferredWidth(50);
        jTabla.getColumnModel().getColumn(1).setPreferredWidth(160);
        jTabla.getColumnModel().getColumn(2).setPreferredWidth(160);
        jTabla.getColumnModel().getColumn(3).setPreferredWidth(160);
    }//Fin de la clase setModeloTabla().
    
    
     /**
     * 
     * @return 
     */
    public DefaultTableModel getModeloTabla(){
        return (DefaultTableModel) jTabla.getModel();
    }
        
    
    /**
     * 
     * @return 
     */
    public JTable getJTActividad(){
        return this.jTabla;
    }
    
    /**
     * 
     * @param listener 
     */
    public void setActionListener(ActionListener listener){
        jAgregar.addActionListener(listener);
    }

    /**
     * 
     * @param listener 
     */
    public void setWindowListener(ActividadController listener){
        this.addWindowListener(null);
    }
    
    /**
     * 
     * @param listener 
     */
    public void setMouseListener(ActividadController listener){
        this.addMouseListener(listener);
    }

    public JButton getjbAgregar(){
        return jAgregar;
    }
    

    
}//Fin de la clase ActividadView.